unit ulistacliente;

interface

uses
  variants, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, DBTables, Grids, DBGrids, ExtCtrls, ComCtrls, Buttons;

type

   THackDBGrid = class(TDBGrid);

  Tflistacliente = class(TForm)
    Panel1: TPanel;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    Label1: TLabel;
    StatusBar1: TStatusBar;
    Panel5: TPanel;
    SpeedButton1: TSpeedButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Edit1Change(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SpeedButton1Click(Sender: TObject);
  private
  procedure AppHint(Sender : TObject);
    { Private declarations }
  public
  st : string;
    { Public declarations }
  end;

var
  flistacliente: Tflistacliente;

implementation

uses upedido, UNota, ureceber, Unpagar, udm;



procedure tflistacliente.AppHint(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := Application.Hint;
end;

{$R *.DFM}

procedure Tflistacliente.FormClose(Sender: TObject; var Action: TCloseAction);
begin
       Application.OnHint := nil;
        flistacliente.release;
end;

procedure Tflistacliente.Edit1Change(Sender: TObject);
begin
        fdm.tbcliente.setrange ([edit1.text], ['Z']);
end;

procedure Tflistacliente.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);

begin

        if key = 13 then
         DBGrid1DblClick(self);

        if key = 27 then close;

        if key = 40 then fdm.tbcliente.next;
        if key = 38 then fdm.tbcliente.prior;
end;

procedure Tflistacliente.FormActivate(Sender: TObject);
begin

THackDBGrid(DBGrid1).FixedCols := 4;
 (fdm.tbcliente.fieldbyname ('codigo') as tfloatfield).displayformat := '000000';
end;

procedure Tflistacliente.DBGrid1DblClick(Sender: TObject);
begin
         if st = 'pedido' then begin
         fpedido.tbpedido.edit;
         fpedido.tbpedido['codigo'] := fdm.tbcliente['codigo'];


         end else if st = 'nota' then begin
         fnota.tbnota.edit;
         fnota.tbnota['codigo'] := fdm.tbcliente['codigo'];
         fnota.pclienteexecute(self);

         end else if st = 'receber' then begin
         fdm.tbreceber.edit;

         end else if st = 'pagar' then begin
         fdm.tbpagar.edit;
         fdm.tbpagar['codigo'] := fdm.tbcliente['codigo'];
         end;

          close;
end;

procedure Tflistacliente.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = 13 then
         DBGrid1DblClick(self);

        if key = 27 then close;
end;

procedure Tflistacliente.FormCreate(Sender: TObject);
begin
Application.OnHint := AppHint;
end;

procedure Tflistacliente.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Comp: Trichedit; // * variável Comp da classe TMemo
  texto : string;
begin

  if key = vk_f1 then begin

  Comp := Trichedit.Create (Self);  // * cria o componente Memo
  Comp.Parent := Self;    // * exibe o componente criado

  if fileexists (extractfilepath(paramstr(0)) + '\ajuda\ajudalistacliente.txt') then
   comp.lines.loadfromfile (extractfilepath(paramstr(0)) + '\ajuda\ajudalistacliente.txt');

  texto := comp.Text;
  comp.Destroy;

  Showmessage (texto);
  end;

end;

procedure Tflistacliente.SpeedButton1Click(Sender: TObject);
var
MSG, st: STRING;
begin

   if fdm.tbcliente['nomefantasia'] <> null then
    st := fdm.tbcliente['nomefantasia'];

    with fdm.query1 do begin
     close;
      sql.clear;
       sql.add ('select distinct nome from tbpedidoitem where operacao ="P" and fantasia = "'+ st+'"');
        open;
         end;

    while not fdm.query1.Eof do begin
    if fdm.query1['nome'] <> null then
    msg := msg + fdm.query1['nome']+ #13;
    fdm.query1.next;
    end;



    showmessage('PRODUTOS CONSUMIDOS:' + #13 + #13 + msg);


end;

end.
